package com.example.community.config;

import com.example.community.controller.intercepter.AlphaInterceptor;
import com.example.community.controller.intercepter.LoginRequiredInterceptor;
import com.example.community.controller.intercepter.LoginTicketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//    @Autowired
//    private AlphaInterceptor alphaInterceptor;

    @Autowired
    LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    private LoginRequiredInterceptor loginRequiredInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(alphaInterceptor)//这个拦截器会拦截一切请求, 需要设置例外
//                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png",
//                        "/**/*.jpg", "/**/*.jpeg")//静态资源随便访问
//                .addPathPatterns("/register", "/login");//设置他能访问的路径
        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png",
                        "/**/*.jpg", "/**/*.jpeg");
        registry.addInterceptor(loginRequiredInterceptor)
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png",
                        "/**/*.jpg", "/**/*.jpeg");//不处理静态资源, 节约性能

    }
}
